import java.time.Duration;
import java.time.LocalDateTime;
import java.time.chrono.ChronoLocalDate;
import java.util.Random;

public class Demo3 {
    public static int sumThread1;

    public static int sumThread2;

    public static void main(String[] args) throws InterruptedException {
        Random random = new Random();
        Object locker = new Object();

        int[] arr = new int[100000000];
        int n = 100000000;

        for (int i = 0; i < n; i++) {
            arr[i] = random.nextInt(100) + 1;
        }

        Thread thread1 = new Thread(() -> {
            for (int i = 0; i < n; i += 2) {
//                synchronized(locker) {
                    sumThread1 += arr[i];
//                }
            }
        });

        Thread thread2 = new Thread(() -> {
            for (int i = 1; i < n; i += 2) {
//                synchronized(locker) {
                    sumThread2 += arr[i];
//                }
            }
        });

        LocalDateTime start = LocalDateTime.now();

        thread1.start();
        thread2.start();
        thread1.join();
        thread2.join();

        LocalDateTime end = LocalDateTime.now();

        Duration dur= Duration.between(start, end);

        System.out.println(sumThread1 + sumThread2);
        System.out.println(dur);
    }
}
